package net.esj.basic.plugins.spring.factory.bean;

import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import net.esj.basic.core.engine.factory.bean.BeanFactory;

public class SpringBeanFactory implements BeanFactory,ApplicationContextAware {

	private ApplicationContext context;
	
	@Override
	public Object getBean(String name) {
		return context.getBean(name);
	}

	@Override
	public Object getBean(String name, Object... args) {
		return context.getBean(name, args);
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.context = applicationContext;
	}

	@Override
	public <T> Map<String, T> getBeansByType(Class<T> clazz) {
		return context.getBeansOfType(clazz,false,true);
	}

	@Override
	public <T> T getBean(Class<T> clazz) {
		return context.getBean(clazz);
	}


}
